
var app = angular.module('dealEdit', []);


//推荐公司列表
$(".company-data-ajax").select2({
    ajax: {
        url: "/smtool_project/api/dicStock/getStockListInStockPool",
        dataType: 'json',
        delay: 250,
        data: function (params) {
            return {
                name: params.term
            };
        },
        processResults: function (data, params) {
            params.page = params.page || 1;
            var newdata = $.map(data.obj, function (obj) {
                obj.id = obj.id || obj.rowId; // replace pk with your identifier
                obj.text = obj.text ||obj.stockCode+" "+ obj.name;
                return obj;
            });

            return {
                results: newdata,
                pagination: {
                    more: (params.page * 30) < data.total_count
                }
            };
        },
        cache: true
    },
    escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
    placeholder:"请选择上市公司",
    minimumInputLength: 2
});

app.controller('dealEditController', function ($scope,$http) {

    $scope.deal = {
        stockId : '',
        groupId : groupId,
        price:'',
        num:'',
        cost:'',
        dealDate:'',
        type:type,
    }
    $scope.typeName = type==1?'买入':'卖出';
    // getData();
    // function getData() {
    //     $http.post("../stockdeal/edit",{
    //         params: {
    //             "queryStr":$scope.queryStr
    //         }
    //     }).then(function (result) {
    //         $scope.datas = result?result.data.list:"";
    //     });
    // };
    //
    //
    $scope.createOrUpdate = function() {
        $scope.deal.dealDate = $("#dealDate").val();
        $http.post("../stockdeal/createOrUpdate",{
                    params: {
                        "deal":$scope.deal
                    }
                }).then(function (result) {

                    $scope.message = "交易成功";
                    $scope.code =  result.data.code;
                    if(result.data.code == '404'){
                       //tle = '交易失败';
                        $scope.message = result.data.message;
                    }
            console.log($scope.message)
                        $('#my-alert').modal();

                });
    };
    $scope.back = function(){
        if($scope.code && $scope.code != '404')
            history.go(-1);
    }
});

